<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改公告板管理')" />
</head>
<style>
    .fileinput-button {
        position: relative;
        overflow: hidden;
        background: #fabe00;
        width: 70px;
        height: 30px;
        color: #fff;
        font-size: 14px;
        text-align: center;
        border: 0;
        border-radius: 5%;
        line-height: 30px;
    }
    .fileinput-button:hover {
        background: #FF8650;
    }
    .fileinput-button input {
        position: absolute;
        top: 0;
        right: 0;
        margin: 0;
        opacity: 0;
        -ms-filter: 'alpha(opacity=0)';
        font-size: 200px;
        direction: ltr;
        cursor: pointer;
    }
    /* Fixes for IE < 8 */
    @media screen\9 {
        .fileinput-button input {
            filter: alpha(opacity=0);
            font-size: 100%;
            height: 100%;
        }}
</style>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-board-edit" th:object="${callBoard}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">公告具体链接：</label>
                <div class="col-sm-8">
                    <input name="url" th:field="*{url}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">公告封面：</label>
                <div class="col-sm-10">
                    <input name="photo" id="pho" class="form-control" type="hidden">
                    <a id="url"><img th:src="*{photo}" style="width: 400px;height: 300px"></a>
                    <div class="fileinput-button">
                        封面更改<input type="file" id="image" accept="image/*">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">公告(是否)上线：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}" required>
                        <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">公告(是否)置顶：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'stick_' + dict.dictCode}" name="stick" th:value="${dict.dictValue}" th:field="*{stick}" required>
                        <label th:for="${'stick_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/board";
        $("#image").change(function () {
            var data = new FormData();
            data.append("file", $("#image")[0].files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    // alert(JSON.stringify(result))
                    if (result.code == web_status.SUCCESS) {
                        $("#url img").attr("src",result.fileName)
                        $("#pho").val(result.fileName)
                    }
                },
                error: function(error) {
                    alert("图片上传失败。");
                }
            });
        })
        $("#form-board-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-board-edit').serialize());
            }
        }
    </script>
</body>
</html>